<<<<<<< HEAD:三子棋的实现/game.c.txt
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include"game.h"
#define ROW 3
#define COL 3


void initboard(char board[ROW][COL], int row, int col)
{
	{
		int i, j;
		for (i = 0; i < ROW; i++)
		{
			for (j = 0; j < COL; j++)
			{
				board[i][j] = ' ';
			}
		}
	}
}

void playermove(char board[ROW][COL], int row, int col)
{
	printf("玩家走>\n");
	printf("请输入坐标\n");
	int a, b;
	
	while (1)
	{
		scanf("%d%d", &a, &b);
		if (a <= ROW&&b <= COL && a > 0 && b > 0)
		{
			if (board[a - 1][b - 1] == ' ')
			{
				board[a - 1][b - 1] = '*';//*作为玩家下的棋子
				return 0;
			}
			else
			{
				printf("改坐标被占用，请重新输入\n");
			}
		}
		else
		{
			printf("坐标不符，请重新输入\n");
		}
	}
}



void displayboard(char board[ROW][COL], int row, int col)
{
	int i, j;

	for (i = 0; i < ROW; i++)
	{
		for (j = 0; j < COL; j++)
		{
			printf(" %c ", board[i][j]);
			if (j < COL - 1)
			{
				printf("|");
			}
		}
		printf("\n");
		//打印分隔符
		if (i < COL - 1)
		{
			for (j = 0; j < ROW; j++)
			{
				printf("--- ");
			}
		}
		printf("\n");
	}
	
}



void computer(char board[ROW][COL], int row, int col)
{
	printf("电脑走\n");
	int a, b;
	srand((unsigned int)time(NULL));
	while (1)
	{
		a = rand() % 3;
		b = rand() % 3;
		if (board[a][b] == ' ')//表示的是电脑输入的
		{
			board[a][b] = '#';
			return 0;
		}
	}
}

char isfull(char board[ROW][COL], int row, int col)
{
	int i, j;
    for (i = 0; i < ROW; i++)
	{
		for (j = 0; j < COL; j++)
		{
			if (board[i][j] == ' ')
			{
				return 'C';//说明还有空格，游戏继续
			}
		}
    }
	return 'Q';//表示已经满了
}


char iswiner_full(char board[ROW][COL], int row, int col)
{
	int i, j;
	char ret = isfull(board, ROW, COL);
	for (i = 0; i < ROW; i++)
	{
		for (j = 0; j < COL; j++)
		{
			
			     if (board[0][j] == board[1][j] && board[1][j] == board[2][j]&&board[2][j]!=' ')
				return board[1][j];
			else if (board[i][0] == board[i][1] && board[i][1] == board[i][2]&&board[i][2]!=' ')
				return board[i][1];
			else if (board[0][0] == board[1][1] && board[1][1] == board[2][2]&&board[2][2]!=' ')
				return board[1][1];
			else if (board[0][2] == board[1][1] && board[1][1] == board[2][0]&&board[2][0]!=' ')
				return board[1][1];
		}
	}
     if (ret == 'Q')
	return 'Q';
	else if (ret == 'C')
	return 'C';
=======
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include"game.h"
#define ROW 3
#define COL 3


void initboard(char board[ROW][COL], int row, int col)
{
	{
		int i, j;
		for (i = 0; i < ROW; i++)
		{
			for (j = 0; j < COL; j++)
			{
				board[i][j] = ' ';
			}
		}
	}
}

void playermove(char board[ROW][COL], int row, int col)
{
	printf("玩家走>\n");
	printf("请输入坐标\n");
	int a, b;
	
	while (1)
	{
		scanf("%d%d", &a, &b);
		if (a <= ROW&&b <= COL && a > 0 && b > 0)
		{
			if (board[a - 1][b - 1] == ' ')
			{
				board[a - 1][b - 1] = '*';//*作为玩家下的棋子
				return 0;
			}
			else
			{
				printf("改坐标被占用，请重新输入\n");
			}
		}
		else
		{
			printf("坐标不符，请重新输入\n");
		}
	}
}



void displayboard(char board[ROW][COL], int row, int col)
{
	int i, j;

	for (i = 0; i < ROW; i++)
	{
		for (j = 0; j < COL; j++)
		{
			printf(" %c ", board[i][j]);
			if (j < COL - 1)
			{
				printf("|");
			}
		}
		printf("\n");
		//打印分隔符
		if (i < COL - 1)
		{
			for (j = 0; j < ROW; j++)
			{
				printf("--- ");
			}
		}
		printf("\n");
	}
	
}



void computer(char board[ROW][COL], int row, int col)
{
	printf("电脑走\n");
	int a, b;
	srand((unsigned int)time(NULL));
	while (1)
	{
		a = rand() % 3;
		b = rand() % 3;
		if (board[a][b] == ' ')//表示的是电脑输入的
		{
			board[a][b] = '#';
			return 0;
		}
	}
}

char isfull(char board[ROW][COL], int row, int col)
{
	int i, j;
    for (i = 0; i < ROW; i++)
	{
		for (j = 0; j < COL; j++)
		{
			if (board[i][j] == ' ')
			{
				return 'C';//说明还有空格，游戏继续
			}
		}
    }
	return 'Q';//表示已经满了
}


char iswiner_full(char board[ROW][COL], int row, int col)
{
	int i, j;
	char ret = isfull(board, ROW, COL);
	for (i = 0; i < ROW; i++)
	{
		for (j = 0; j < COL; j++)
		{
			
			     if (board[0][j] == board[1][j] && board[1][j] == board[2][j]&&board[2][j]!=' ')
				return board[1][j];
			else if (board[i][0] == board[i][1] && board[i][1] == board[i][2]&&board[i][2]!=' ')
				return board[i][1];
			else if (board[0][0] == board[1][1] && board[1][1] == board[2][2]&&board[2][2]!=' ')
				return board[1][1];
			else if (board[0][2] == board[1][1] && board[1][1] == board[2][0]&&board[2][0]!=' ')
				return board[1][1];
		}
	}
     if (ret == 'Q')
	return 'Q';
	else if (ret == 'C')
	return 'C';
>>>>>>> c6792f08e0f7b0387537b9b94b0df1a50faecb6d:三子棋的实现/game.c
}